<template>
    <div class="good-desc-container">
        <div class="input-cu-group">
            <label for="good-name">商品列表描述</label>
            <input id="good-name" placeholder="请输入商品的描述" :value="goodDesc" @change="updateValue('goodDesc',$event)"/>
            <label class="warn-tip" v-if="goodDesc==''">*</label>
        </div>
        <div class="input-cu-group">
            <label for="good-name">商品详情描述</label>
            <textarea  @change="updateValue('goodDetailDesc',$event)" :value="goodDetailDesc"></textarea>
            <label class="warn-tip" v-if="goodDetailDesc===''">*</label>
        </div>
        <div class="icon-container">
            <div class="text-container">
                <h5>详细页展示图(最多三张)</h5>
                <input type="text" placeholder="请输入图库中图片的名称" v-model="nowUrl">
                <button @click="uploadImg">上传</button>
            </div>
            <div class="img-container">
                <div class="img-item" v-for="(item,index) in detailBannerList" :key="item">
                    <img :src="format(item)"/>
                    <div class="delete-img" title="点击删除图片" @click="del(index)"></div>
                </div>
            </div>
        </div>
        <button :class="canSubmit?'canSub':'cantSub'" @click="submitGood">提交商品</button>
    </div>
</template>

<script>
import {mapState,mapGetters, mapMutations} from 'vuex'
export default {
    data(){
        return {
            nowUrl:''
        }
    },
    computed:{
        ...mapState(['goodDesc','goodDetailDesc','detailBannerList']),   
        ...mapGetters(['canSubmit'])
    },
    methods:{
        ...mapMutations(['addDetailBanner','delDetailBanner','setNewValue','uploadGood']),
        del(index){
            this.delDetailBanner(index)
        },
        uploadImg(){
            this.addDetailBanner(this.nowUrl)
        },
        updateValue(prop,e){
            this.setNewValue({prop:prop,newValue:e.target.value})
        },
        submitGood(){
            this.uploadGood()
        },
        format(name){
            return this.$http.defaults.baseURL+'/images/'+name
        }
    }   
}   
</script>

<style lang="less">
    .good-desc-container{
        .cantSub{
            width: 30%;
            position: absolute;
            box-sizing: border-box;
            padding: 15px;
            border-radius: 25px;
            color: #ffffff;
            background-color: #797878;
            border: 0px solid #d12311;
            bottom: 50px;
            left: 150px;
        }
        .canSub{
            width: 30%;
            position: absolute;
            box-sizing: border-box;
            padding: 15px;
            border-radius: 25px;
            color: #ffffff;
            background-color: #1f3c48;
            border: 0px solid #d12311;
            bottom: 50px;
            left: 150px;
        }
        .canSub:hover{
            background-color: #11222a;
        }
        .icon-container{
            display: flex;
            flex-direction: row;
            background-color: #f6f6f6;
            border-radius: 20px;
            box-sizing: border-box;
            padding: 20px;
            margin: 20px;
            .img-container{
                display: flex;
                align-items: center;
                .img-item{
                    display: flex;
                    img{
                        width: 200px;
                        border-radius: 20px;
                    }
                    .delete-img{
                        width: 20px;
                        height: 20px;
                        background-image: url(@/assets/close2.png);
                        background-position: 50%;
                        background-size:cover
                    }  
                    .delete-img:hover{
                        background-image: url(@/assets/close1.png);
                        cursor: pointer;
                    }     
                }
                
                margin-right: 10px;
            }
            .text-container{
                flex: 1;
                .warn-tip{
                    margin-left: 10px;
                    text-align: left;
                    color: #C00000;
                    font-weight: bolder;
                }
                h5{
                    margin: 0;
                    font-weight: 500;
                    color: #797878;
                }
                input{
                    box-sizing: border-box;
                    padding: 5px 10px;
                    border: 0.5px solid #a2a2a2;
                    margin: 20px 0;
                    border-radius: 7px;
                }
                button{
                    border: 0 solid #ffffff;
                    margin-left: 10px;
                    box-sizing: border-box;
                    padding: 10px;
                    background-color: #bababa;
                    border-radius: 5px;
                    color: #d12311;
                    font-size: 15px;
                }
                button:hover{
                    background-color: #a2a2a2;
                }
            }
            img{
                width: 150px;
                height: 150px;
                border-radius: 20px;
            }
            
        }
        .input-cu-group{
            margin-bottom: 30px;
            position: relative;
            display: flex;
            align-items: center;
            .warn-tip{
                margin-left: 10px;
                text-align: left;
                color: #C00000;
                font-weight: bolder;
            }
            label{
                margin-right: 10px;
                width: 160px;
                text-align: right;
                color: #797878;
            }
            input{
                box-sizing: border-box;
                padding: 5px 10px;
                width: 50%;
                border: 0.5px solid #a2a2a2;
                border-radius: 7px;
            }
            textarea{
                width: 50%;
                height: 120px;
                resize: none;
                border-radius: 15px;
                border: 0.5px solid #a2a2a2;
            }
            select{
                width: 50%;
                box-sizing: border-box;
                padding: 5px 10px;
                border: 0.5px solid #a2a2a2;
                border-radius: 7px;
            }
        }
    }
</style>